package com.example.demo.controller;

import com.example.comon.domain.R;
import com.example.demo.domain.Bo.AddEmployeeBo;
import com.example.demo.domain.Bo.EmployeeBo;
import com.example.demo.domain.Employee;
import com.example.demo.domain.Vo.EmployeeVo;
import com.example.demo.service.IEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
@Api(value = "employee",tags = "员工控制器")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    @GetMapping("/getEmployee")
    @ApiOperation("获取员工列表")
    public R<List<EmployeeVo>> getEmployee(EmployeeBo bo){
        Employee employee = new Employee();
        employee.setEmployeeNum(bo.getEmployeeNum());
        List<EmployeeVo>list = employeeService.selectEmployee(employee);
        return R.success(list);
    }

    @PostMapping("/addEmployee")
    @ApiOperation("新增员工")
    public R<Employee> addEmployee(@RequestBody AddEmployeeBo bo){
        Employee employee = new Employee();
        employee.setEmployeeNum(bo.getEmployeeNum());
        employee.setName(bo.getName());
        employee.setSex(bo.getSex());
        employee.setNumber(bo.getNumber());
        employee.setIdCard(bo.getIdCard());
        employee.setDepartmentId(bo.getDepartmentId());
        employee.setOrigin(bo.getOrigin());
        employeeService.insertEmployee(employee);
        return R.success(employee);
    }

    @PostMapping("/updateEmployeeById")
    @ApiOperation("修改员工")
    public R updateEmployeeById(@RequestBody Employee employee){
        employeeService.updateEmployeeById(employee);
        return R.success();
    }

    @DeleteMapping("/delEmployeeById")
    @ApiOperation("删除员工")
    public R delEmployeeById(long employeeId){
        employeeService.delEmployeeById(employeeId);
        return R.success();
    }

}
